package com.yoyo.itravel.service.impl;

import com.yoyo.itravel.bean.FlightOrder;
import com.yoyo.itravel.dao.IFlightOrderDao;
import com.yoyo.itravel.exceptions.FlightOrderException;
import com.yoyo.itravel.service.IFlightOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;


/**
 * @author liuchaojie
 * @version 1.0
 * @Description 订单操作类服务层接口实体类【服务层】
 * @date 2020/6/18 18:47
 */
@Service
public class FlightOrderServiceImpl implements IFlightOrderService {
    @Autowired
    private IFlightOrderDao flightOrderDao;

    /**
     * 增加机票订单
     * @param flightOrder
     * @return
     * @throws FlightOrderException
     */
    @Override
    public int insert(FlightOrder flightOrder) throws FlightOrderException {
        try {
            return flightOrderDao.insert(flightOrder);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new FlightOrderException("增加机票订单失败！...");
        }
    }

    /**
     * 删除机票订单
     * @param flightOrder
     * @return
     * @throws FlightOrderException
     */
    @Override
    public int delete(FlightOrder flightOrder) throws FlightOrderException {
        try {
            return flightOrderDao.delete(flightOrder);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new FlightOrderException("删除机票订单失败！...");
        }
    }

    /**
     * 查询机票订单
     * @param orderId
     * @return
     * @throws FlightOrderException
     */
    @Override
    public FlightOrder selectByFlightOrderId(String orderId) throws FlightOrderException {
        try {
            return flightOrderDao.selectByFlightOrderId(orderId);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new FlightOrderException("查询机票订单失败！...");
        }
    }

    /**
     * 修改机票订单
     * @param flightOrder
     * @return
     * @throws FlightOrderException
     */
    @Override
    public int update(FlightOrder flightOrder) throws FlightOrderException {
        try {
            return flightOrderDao.update(flightOrder);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new FlightOrderException("修改机票订单失败！...");
        }
    }
}
